# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_pyname=SCons
_realname=scons
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.9.1
pkgrel=1
pkgdesc="Extensible Python-based build utility (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64' 'mingw32')
url="https://scons.org"
msys2_repository_url="https://github.com/SCons/scons"
msys2_references=(
  'purl: pkg:pypi/scons'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=(!strip)
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-mingw-path.patch"
        "0002-fix-missing-man-pages.patch")
sha256sums=('bacac880ba2e86d6a156c116e2f8f2bfa82b257046f3ac2666c85c53c615c338'
            '4416b87da2d7e2879d6f2fd13796887b0a0de3dfffb9be3ec2f565f794a72048'
            'd6c7e88bd810bb32309cded3ddb3ee913b3b06872238e60bfd0f1cd615eaf936')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-fix-mingw-path.patch"
  patch -Np1 -i "${srcdir}/0002-fix-missing-man-pages.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
